package com.qf.lanzhou.blog.api.controller;


import com.qf.lanzhou.blog.api.pojo.entity.Article;
import com.qf.lanzhou.blog.api.service.CreationService;
import com.qf.lanzhou.blog.api.service.impl.CreationServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @Author Nerly
 * @Date 2020/12/15 17:25
 * @JDK 1.8
 * @Version 1.0
 */
@WebServlet("/creation.do")
public class CreationServlet extends BaseServletPost {
    private CreationService creationService = new CreationServiceImpl();
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        Article article = paramsToEntity(req, Article.class);
        String errMsg = creationService.checkExist(article);
        if (errMsg!=null){
            //返回前端错误信息
            failedResultWrite(errMsg,resp);
            return;
        }
        //返回成功信息
        successResultWrite(article,resp);
    }
}
